<?php if ( ! defined('WDK_PATH')) exit('No direct script access allowed');
require_once PROJECT_PATH.'core/AdminController.php';
class Login extends AdminController
{
	function __construct()
	{
		parent::__construct();
	}
	
	protected function _init() 
	{
		
	}
	
	public function index($url='')
	{
		$this->_index();
		/*****************************************************************************************************************************
		 * BASIC VARS
		*****************************************************************************************************************************/
		$assign_data = array('url'=>$url);
		/****************************************************************************************************************************/
		try
		{
			
		}
		catch(WException $e)
		{
			parent::_error($e);
		}
		/*****************************************************************************************************************************
		* RESULT
		*****************************************************************************************************************************/
		parent::_layout('admin_blank');
		parent::_view($assign_data);
		/****************************************************************************************************************************/
	}
	
	protected function _index()
	{
		if(parent::_isPost() == false) return;
		/*****************************************************************************************************************************
		 * BASIC VARS
		*****************************************************************************************************************************/
		$user_login_id		= (string) post('user_login_id');
		$user_login_passwd	= (string) post('user_login_passwd');
		$url				= (string) post('url');
		$user	= Wdk::get('User');
		/****************************************************************************************************************************/
		try
		{
			$user->login($user_login_id, $user_login_passwd);
			if($user['user_type'] != USER_TYPE_ADMIN)
			{
				throw new NoRecordException();
			}
			$this->session->set("user_seq"		, $user['user_seq']);
			$this->session->set("user_login_id"	, $user['user_login_id']);
			$this->session->set("user_name"		, $user['user_name']);
			$this->session->set("user_nick"		, $user['user_nick']);
			parent::_redirect(base64_decode($url));
		}
		catch(UserPasswordException $e)
		{
			parent::_script(array("alert('비밀번호를 확인하십시오.');", "history.back();"));
		}
		catch(NoRecordException $e)
		{
			parent::_script(array("alert('존재하지 않는 아이디 입니다.');", "history.back();"));
		}
		catch(WException $e)
		{
			parent::_error($e);
		}
	}
	
	public function logout()
	{
		$this->session->destroy();
		parent::_redirect("/admin");
	}
}